package com.yjd.bi.statistic.control;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.yjd.bi.comm.utils.BiDateUtil;
import com.yjd.bi.report.enums.TimeType;
import com.yjd.bi.report.model.EChartsModel;
import com.yjd.bi.user.service.IInvestUserStatisticsService;
import com.yjd.comm.annotation.DateString;
import com.yjd.comm.annotation.ServiceRemoteProxy;
import com.yjd.comm.base.control.BaseControl;
import com.yjd.comm.rpm.RpmServiceKeyEnum;
import com.yjd.comm.util.FrameUtil;

@Controller
@Scope("prototype")
@RequestMapping("/userinvest")
public class UserInvestControl extends BaseControl{
	
	@ServiceRemoteProxy(serviceUrlResouceKey = RpmServiceKeyEnum.RPM_BI_SERVICE_KEY)
	private IInvestUserStatisticsService investUserStatisticsService;
	
	
	/**
	 * 登录频率统计页面
	 * 
	 * @return
	 * @throws Exception
	 *             String
	 */
	@RequestMapping("index")
	public String index() throws Exception {
        request.setAttribute("start", "2013-12-21");
        request.setAttribute("end", BiDateUtil.initBiDate());
        return "user_invest.index";
	}
	
	/**
	 * 登录频率统计
	 * 
	 * @throws Exception
	 *             void
	 */
	@RequestMapping("investcount")
	public void investcount(@RequestParam(required = false) Integer timeType,
			@DateString String timeFrom,
			@RequestParam(required = false) String field) throws Exception {
		EChartsModel echartsMoel = investUserStatisticsService.getDates(
				TimeType.getType(timeType), Long.valueOf(timeFrom), field);
		super.successData(FrameUtil.newHashMap("option", echartsMoel));
	}

	@RequestMapping("/sleepUser")
	public void sleepUser(@RequestParam(required = false) Integer timeType,
							@DateString String timeFrom,
							@RequestParam(required = false) Integer timeSpan) throws Exception {
		EChartsModel echartsMoel = investUserStatisticsService.getSleepUser(
				TimeType.getType(timeType), Long.valueOf(timeFrom), timeSpan);
		super.successData(FrameUtil.newHashMap("option", echartsMoel));
	}
}
